package approve.dao;
import java.sql.ResultSet;
import model.pojo.Employee;
import models.util.MySqlDataAccessHelper;
public class DeparmentDAO {
	public static Employee getNameDeptByIDEmp(String id,String database){
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();	
		Employee name = new Employee();
		String sql="SELECT deplang.DepartmentName,emp.FullName FROM department dep,department_lang deplang,employee emp  WHERE dep.IDDepartment = deplang.IDDepartment AND dep.IDDepartment = emp.IDDepartment and emp.IDEmployee = '"+id+"'";
		try {
			mysql.open(database);
			ResultSet rs = mysql.executeQuery(sql);
			if (rs.next()) {	
				name.setFullName(rs.getString("FullName"));
				name.setDepartmentName(rs.getString("DepartmentName"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				mysql.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return name;
	}
	
	public static Employee getNameDept(String id,String database){
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();	
		Employee name = new Employee();
		String sql="SELECT deplang.DepartmentName FROM department dep,department_lang deplang,employee emp  WHERE dep.IDDepartment = deplang.IDDepartment AND dep.IDDepartment = emp.IDDepartment and emp.IDEmployee = '"+id+"'";
		try {
			mysql.open(database);
			ResultSet rs = mysql.executeQuery(sql);
			if (rs.next()) {	
				name.setDepartmentName(rs.getString("DepartmentName"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				mysql.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return name;
	}
}